<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends MX_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct(){
		parent::__construct();
	}
	public function Index()
	{
		
		$u = new Login();
		$u->name = "102030e";
		$u->password = "301346";

        $data['objeto'] = $u;
        if ($u->Very_Login()) 
        {
        $newdata = array(
                   'name'  => $u->name,
                   'email' => $u->password,
                   'acess' => $u->storage->user_level,
                   'logged_in' => TRUE
               );
              $session_id = $this->session->set_userdata($newdata);
             
        } 


		$this->gravatar = new emberlabs\gravatarlib\Gravatar();
		$this->gravatar->enableSecureImages();
		$this->gravatar->setAvatarSize('150');
		$data['gravatar'] = $this->gravatar->buildGravatarURL($u->storage->email);
		$this->load->view('welcome_message', $data);
	}
	public function Login(){		
		// LOAD LIBRARIES
		$this->load->library(array('form_validation', 'session'));
		
		// LOAD HELPERS
		$this->load->helper(array('form', 'url'));

		// SET VALIDATION RULES
		$this->form_validation->set_rules('user_name', 'username', 'required');
		$this->form_validation->set_rules('user_pass', 'password', 'required');
		$this->form_validation->set_error_delimiters('<em>','</em>');
		
		// has the form been submitted and with valid form info (not empty values)
		if($this->input->post('login'))
		{
			if($this->form_validation->run())
			{
				$u = new Login();
				$u->name = $this->input->post('user_name');
				$u->password = $this->input->post('user_pass');
				
				if ($u->Very_Login()) 
				{

						// user has been logged in
						die("USER LOGGED IN!");
				}
				else
				{
					$this->session->set_flashdata('message', $u->error->login);
					redirect('welcome/login');
				}
			}
		}
		$data['modules'] = array(
		'welcome/index',
		);
		$this->load->view('login_page', $data);	
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */